/* $RCSFile: TaxManager.ascx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice.ECommerce/PageModules/ECommerce/TaxManager.ascx.cs $
 * $log$
 * Revision 21 2010/08/09 11:08:12  christian.surieux
 *   Added Log comment to all .ascx .aspx .master files
 * Revision 8 2010/08/09 10:07:05  christian.surieux
 *   Added Log comment to all cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Xml;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Globalization;

using AddonNice.Diagnostics;
using AddonNice.Security;
using AddonNice.Configuration;
using AddonNice.Helpers;
using AddonNice.UI;
using AddonNice.UI.WebControls;
using AddonNice.UI.DataTypes;
using AddonNice.Settings;

using AddonNice.CRMWrapper;

using AddonNice.ECommerce;
using AddonNice.ECommerce.UI;
using AddonNice.ECommerce.UI.WebControls;
using AddonNice.Settings.ECommerce;
using AddonNice.CRMWrapper.ECommerce;

using Telerik.Web.UI;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.PageModules.ECommerce
{
    #region TraceSwitch for TaxManager
    public class TaxManagerTrace
	{
		static public ADNTraceSwitch	Sw	=	new ADNTraceSwitch("TaxManagerTrace","Local Trace Switch for TaxManager");
	}
	#endregion TraceSwitch for TaxManager

	/// <summary>
	///	Manages taxes in new CRM entity adn_taxes
	/// </summary>
	public partial class TaxManager : ECommerceModule 
	{
		#region Global Implementation
        
        public override Guid GuidID 
		{
			get
			{
				return new Guid(EComStStr.TaxManGuid);
			}
		}

        public override bool DependsFromCustomCrmEntities
        {
            get{ return true;}
        }
        
        /// <summary>
        /// SortedList of entities/version from which this module depends, schema name is the key, version is a string in the form major.minor
        /// </summary>
        public override SortedList<string,string> RelatedCustomEntities
        {
            get
            {
                SortedList<string,string> Lst =   new SortedList<string,string>();
                Lst.Add(EComStStr.adntaxes,"1.0");
                return Lst;
            }
        }

        #endregion Global Implementation

        void TaxManager_Load(object sender, EventArgs e)
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose || TaxManagerTrace.Sw.TraceVerbose )
				Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]TaxManager TaxManager_Load BEG isPostBack: {0}.",IsPostBack),
                    ( ModuleTraceSwitch.Sw.TraceVerbose) ? ModuleTraceSwitch.Sw.Info:TaxManagerTrace.Sw.Info);
//			if ( !IsPostBack ) 
			{
			}
            if ( ModuleTraceSwitch.Sw.TraceVerbose || TaxManagerTrace.Sw.TraceVerbose )
				Trace2.WriteLine("[V]TaxManager TaxManager_Load END.",( ModuleTraceSwitch.Sw.TraceVerbose) ? ModuleTraceSwitch.Sw.Info:TaxManagerTrace.Sw.Info);
		}

        void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            if (TaxManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]TaxManager RadGrid1_NeedDataSource BEG RebindReason: {0}.",e.RebindReason),TaxManagerTrace.Sw.Info);
            DataTable   tbTaxes  =   null;
            try
            {
                tbTaxes = new TaxesCRM().GetAllTaxes();
            }
            catch (Exception ex)
            {
                if (TaxManagerTrace.Sw.TraceError)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]TaxManager RadGrid1_NeedDataSource ex: {0}.",ex),TaxManagerTrace.Sw.Info);
                throw;
            }
            RadGrid1.DataSource     =   tbTaxes;
            if (TaxManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( "[V]TaxManager RadGrid1_NeedDataSource END.",TaxManagerTrace.Sw.Info);
        }
        
        #region Std Control override
 
        public override void Page_PreInit(object sender, EventArgs e)
        {
            // Add a link for the edit page
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]TaxManager Page_PreInit BEG IsPosBack: {0}", IsPostBack),ModuleTraceSwitch.Sw.Info);
            //AddUrl                  =   Config.ModulesPath + "/ECommerce/AddTaxe.aspx";
            base.Page_PreInit(sender, e);
            if (ModuleTraceSwitch.Sw.TraceVerbose)
                Trace2.WriteLine("[V]TaxManager Page_PreInit END.",ModuleTraceSwitch.Sw.Info);
        }

        override protected void OnInit(EventArgs e)
		{
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine("[V]TaxManager OnInit BEG.",ModuleTraceSwitch.Sw.Info);
			InitializeComponent();
			base.OnInit(e);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine("[V]TaxManager OnInit END.",ModuleTraceSwitch.Sw.Info);
		}

        private void InitializeComponent()
        {
            Load                            +=  new EventHandler(TaxManager_Load);
            RadGrid1.NeedDataSource         +=  new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
        }

      #endregion Std Control override
 	}
}
